package com.builder.model;

import com.builder.model.builder.BMWBuilder;
import com.builder.model.builder.BenzBuilder;
import com.builder.model.car.BenzModel;
import com.builder.model.car.CarModel;

import java.util.ArrayList;

public class BuilderMainTest {
    public static void main(String[] args) {
        //测试car 模板模式
        //BuilderMainTest.carTest();
        //测试建造者
        //BuilderMainTest.builderTest();
        //测试建造者 管理
        BuilderMainTest.directorTest();
    }

    public static void carTest() {
        CarModel carModel = new BenzModel();
        //存放汽车的顺序动作
        ArrayList<String> sequence = new ArrayList();
        sequence.add("enginboom");
        sequence.add("start");
        sequence.add("stop");
        sequence.add("enginboom");
        //把动作赋予奔驰
        carModel.setSequence(sequence);
        carModel.run();
    }

    public static void builderTest() {
        ArrayList<String> sequence = new ArrayList();
        sequence.add("enginboom");
        sequence.add("start");
        sequence.add("stop");
        sequence.add("enginboom");
        //要一个奔驰
        BenzBuilder benzBuilder = new BenzBuilder();
        //设置顺序
        benzBuilder.setSequence(sequence);
        // 制造一个奔驰出来
        CarModel benz = benzBuilder.getCarModel();
        benz.run();
        System.out.println("--------------------");
        //要一个通用顺序的宝马
        BMWBuilder bmwBuilder = new BMWBuilder();
        bmwBuilder.setSequence(sequence);
        CarModel bmw = bmwBuilder.getCarModel();
        bmw.run();

    }

    public static void directorTest() {
        Director director = new Director();
        //100辆A类型的车
        for (int i = 0; i < 100; i++) {
            director.getABenzModel();
        }
        //100辆B类型的车
        for (int i = 0; i < 100; i++) {
            director.getBBenzModel();
        }
        //100辆C类型的车
        for (int i = 0; i < 100; i++) {
            director.getCBWMModel();
        }

    }
}
